/*! lzf */

var currentTime = (new Date).toLocaleString()
    , minDate = "";
function owener_time() {
    $("#owner_time").datetimepicker({
        lang: "ch",
        validateOnBlur: !1,
        format: "Y-m-d H:i",
        formatDate: "Y-m-d H:i",
        minDate: minDate,
        maxDate: "2116-5-20 12:30",
        allowTimes: ["8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00"]
    })
}
minDate = (minDate = currentTime.substring(0, 7) + "-" + (Number(currentTime.substring(8, 10)) + 1)).replace("/", "-") + " 8:00",
    $(document).ready(function() {
        $(".ap_change").click(function() {
            var t = $(this).parent().attr("data-id")
                , e = $(this).parent().attr("data-type")
                , a = $(this).parent().attr("data-status");
            $("#change_time_form").attr({
                "data-id": t,
                "data-type": e
            });
            "待确认" == a || "已确认" == a ? ($("#datetimepicker2").val($(this).attr("data-time").substring(0, 16)),
                $("#datetimepicker2").datetimepicker({
                    yearOffset: 0,
                    lang: "ch",
                    validateOnBlur: !1,
                    format: "Y-m-d H:s",
                    formatDate: "Y-m-d H:s",
                    minDate: $(this).attr("data-time"),
                    maxDate: "2116-5-20 8:00",
                    allowTimes: ["8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00"]
                }),
                dialog({
                    title: "变更看房时间",
                    width: 400,
                    height: 70,
                    content: $("#change_time_form"),
                    button: [{
                        value: "确定",
                        callback: function() {
                            return $("#change_time_form").submit(),
                                !1
                        },
                        autofocus: !0
                    }, {
                        value: "取消"
                    }]
                }).showModal()) : alert("当前状态不能变更")
        }),
            $("#change_time_form").validate({
                rules: {
                    fu_time: {
                        required: !0
                    }
                },
                messages: {
                    fu_time: {
                        required: "请输入看房时间"
                    }
                },
                submitHandler: function(t) {
                    var e = {
                        ma_time: $(t).find("#datetimepicker2").val(),
                        apt_type: $(t).attr("data-type"),
                        mem_appointment_id: $(t).attr("data-id")
                    };
                    base.button_loading() && $.post(base.site_url("client/memMng/memAppointment/changeAppointStatus"), e, function(t) {
                        0 == t.code ? base.reload() : (base.alertMsg({
                            text: t.message
                        }),
                            base.reset_button())
                    }, "json")
                }
            }),
            $(".ap_cancel").click(function() {
                this._status = $(this).parent().attr("data-status"),
                    "待确认" == this._status || "已确认" == this._status ? ($("#cancel_appoint_form").attr({
                        "data-id": $(this).parent().attr("data-id"),
                        "data-type": $(this).parent().attr("data-type")
                    }),
                        dialog({
                            title: "取消预约",
                            width: 500,
                            height: 200,
                            content: $("#cancel_appoint_form"),
                            button: [{
                                value: "确定",
                                callback: function() {
                                    return $("#cancel_appoint_form").submit(),
                                        !1
                                },
                                autofocus: !0
                            }, {
                                value: "取消"
                            }]
                        }).showModal()) : alert("预约已取消或结束")
            }),
            $("#cancel_appoint_form").validate({
                rules: {
                    ma_reason: {
                        required: !0
                    }
                },
                messages: {
                    ma_reason: {
                        required: "请输入取消原因"
                    }
                },
                submitHandler: function(t) {
                    var e = {
                        mem_appointment_id: $(t).attr("data-id"),
                        apt_type: $(t).attr("data-type"),
                        ma_reason: $(t).find("#cancel_ma_reason").val()
                    };
                    $.post(base.site_url() + "client/memMng/memAppointment/cancleAppointStatus", e, function(t) {
                        0 == t.code ? base.reload("操作成功") : base.alertMsg({
                            text: t.message
                        })
                    }, "json")
                }
            }),
            $(".ap_advise").click(function() {
                var i = this;
                dialog({
                    title: "投诉",
                    width: 600,
                    height: 200,
                    content: $("#ap_advise_con"),
                    button: [{
                        value: "确定",
                        callback: function() {
                            var e = ""
                                , a = !0
                                , t = $("#ap_advise_con");
                            t.find("input[type=checkbox]").each(function(t) {
                                1 == this.checked && (0 == e.length ? e += this.value : e += "," + this.value,
                                6 == this.value && (a = 6))
                            });
                            var n = {
                                mr_report_item: e,
                                mem_appointment_id: $(i).parent().attr("data-id"),
                                mr_reason: t.find("textarea").val()
                            };
                            return 6 == a && "" == n.mr_reason && (a = !1),
                                0 != e.length && a ? $.post(base.site_url() + "client/memMng/memAppointment/addReport", {
                                    data: JSON.stringify(n)
                                }, function(t) {
                                    0 == t.code ? base.reload() : base.alertMsg({
                                        text: t.message
                                    })
                                }, "json") : 0 == a ? base.alertMsg({
                                    text: "请填写投诉原因"
                                }) : base.alertMsg({
                                    text: "请勾选投诉原因"
                                }),
                                !1
                        },
                        autofocus: !0
                    }, {
                        value: "取消"
                    }]
                }).showModal()
            }),
            $("#datetimepicker").datetimepicker({
                lang: "ch",
                validateOnBlur: !1,
                format: "Y-m-d H:i",
                formatDate: "Y-m-d H:i",
                minDate: minDate,
                maxDate: "2116-5-20 12:30",
                allowTimes: ["8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00"]
            }),
            $("#appoint_form").validate({
                rules: {
                    fu_time: {
                        required: !0
                    }
                },
                messages: {
                    fu_time: {
                        required: "请输入看房时间"
                    }
                },
                submitHandler: function(t) {
                    var e = {
                        apartment_id: GetApartmentId(),
                        fu_name: $(t).find(".name").val(),
                        fu_gender: $(t).find(".radio-selected").attr("data-val"),
                        ma_time: $(t).find("#datetimepicker").val()
                    }
                        , a = window.location.href;
                    $.post(base.site_url() + "client/memMng/memAppointment/addAppointment", e, function(t) {
                        0 == t.code ? (window.location.href = a.split("?")[0],
                            window.opener.location.reload()) : base.alertMsg({
                            text: t.message
                        })
                    }, "json")
                }
            }),
            $(".weixin").click(function() {
                var e = dialog({
                    title: "绑定微信",
                    width: 500,
                    height: 300,
                    padding: 0,
                    cancelDisplay: !1
                }).showModal()
                    , t = {
                    mem_appointment_id: $(this).attr("data-id")
                };
                $.post(base.site_url("client/apart/apart/createUserApptQrcode"), t, function(t) {
                    0 === t.code && e.content('<div class="t-c wx-wrap"><div><img src="' + t.data + '" width="144" height="144" /></div><div class="wx-info"><p>打开微信扫一扫，关注“租房网”微信公众号</p><p>实时接收预约通知，查看公寓联系方式</p></div></div>')
                }, "json")
            }),
            $(".owner_confirm").click(function() {
                var t = $(this).parent().attr("data-status")
                    , e = $(this).parent().attr("data-id")
                    , a = $(this).parent().attr("data-time").substring(0, 16);
                "待确认" == t ? (dialog({
                    title: "预约确认",
                    width: 350,
                    content: '<div class="container"><input value="' + a + '" class="input" id="owner_time"></div>',
                    button: [{
                        value: "确定",
                        callback: function() {
                            var t = {
                                mem_appointment_id: e,
                                ma_time: $("#owner_time").val()
                            };
                            return $.post(base.site_url("client/memMng/memAppointment/effectAppointment"), t, function(t) {
                                0 === t.code ? base.reload() : base.alertMsg({
                                    text: t.message
                                })
                            }, "json"),
                                !1
                        },
                        autofocus: !0
                    }, {
                        value: "取消"
                    }]
                }).showModal(),
                    owener_time()) : alert("当前状态不能执行该操作")
            }),
            $(".owner_change").click(function() {
                var t = $(this).parent().attr("data-status")
                    , e = $(this).parent().attr("data-time").substring(0, 16)
                    , a = $(this).parent().attr("data-id");
                "已确认" == t ? (dialog({
                    title: "变更预约",
                    width: 550,
                    content: '<form id="owner_change_form">  <div class="t-c">  \t<input id="owner_time" value="' + e + '" class="input" style="width:400px;">  </div>\t<div class="t-c ma-top textarea">\t\t<textarea placeholder="变更原因..." name="ma_reason" id="owner_change_reason"></textarea>\t</div></form>',
                    button: [{
                        value: "确定",
                        callback: function() {
                            return $("#owner_change_form").submit(),
                                !1
                        },
                        autofocus: !0
                    }, {
                        value: "取消"
                    }]
                }).showModal(),
                    owener_time(),
                    $("#owner_change_form").validate({
                        rules: {
                            ma_reason: {
                                required: !0
                            }
                        },
                        messages: {
                            ma_reason: {
                                required: "请输入取消原因"
                            }
                        },
                        submitHandler: function(t) {
                            var e = {
                                mem_appointment_id: a,
                                ma_time: $("#owner_time").val(),
                                ma_reason: $(t).find("#owner_change_reason").val()
                            };
                            $.post(base.site_url("client/memMng/memAppointment/changeAppointment"), e, function(t) {
                                0 == t.code ? base.reload() : base.alertMsg({
                                    text: t.message
                                })
                            }, "json")
                        }
                    })) : alert("当前状态不能执行该操作")
            }),
            $(".owner_cancel").click(function() {
                var t = $(this).parent().attr("data-status")
                    , a = $(this).parent().attr("data-id");
                "待确认" == t || "已确认" == t ? (dialog({
                    title: "取消预约",
                    width: 550,
                    content: '<form id="owner_cancel_form">\t<div class="t-c ma-top textarea">\t\t<textarea placeholder="取消原因..." name="ma_reason" id="owner_cancel_reason"></textarea>\t</div></form>',
                    button: [{
                        value: "确定",
                        callback: function() {
                            return $("#owner_cancel_form").submit(),
                                !1
                        },
                        autofocus: !0
                    }, {
                        value: "取消"
                    }]
                }).showModal(),
                    $("#owner_cancel_form").validate({
                        rules: {
                            ma_reason: {
                                required: !0
                            }
                        },
                        messages: {
                            ma_reason: {
                                required: "请输入取消原因"
                            }
                        },
                        submitHandler: function(t) {
                            var e = {
                                mem_appointment_id: a,
                                ma_reason: $(t).find("#owner_cancel_reason").val()
                            };
                            $.post(base.site_url("client/memMng/memAppointment/cancleAppointment"), e, function(t) {
                                0 == t.code ? base.reload() : base.alertMsg({
                                    text: t.message
                                })
                            }, "json")
                        }
                    })) : alert("预约已取消或结束")
            })
    });
